#ifndef _YL_MESSAGE_GROUP_
#define _YL_MESSAGE_GROUP_

using namespace System::Runtime::Serialization;

namespace yoctolog_viewer
{
	ref class LogMessageClass;
	ref class LogMessage;

	[System::SerializableAttribute]
	public ref class LogMessageGroup
	{
	public:
		System::String ^									m_strName;

		System::Collections::Generic::List<unsigned int> ^	m_vecMessageList;
		System::Collections::Generic::Dictionary<LogMessageClass ^, unsigned int>	m_mapClassCounts;

		delegate void OnMessageAddedDelegate(unsigned int uiID);

		OnMessageAddedDelegate ^OnMessageAdded;


		LogMessageGroup()
		{
			m_vecMessageList = gcnew System::Collections::Generic::List<unsigned int>();
		}

		~LogMessageGroup()
		{
			delete OnMessageAdded;

			delete m_vecMessageList;
		}

		// Serialization
		virtual void GetObjectData(System::Runtime::Serialization::SerializationInfo ^info, System::Runtime::Serialization::StreamingContext context)
		{
			info->AddValue("m_strName", m_strName);
			info->AddValue("m_vecMessageList", m_vecMessageList);
		}

		LogMessageGroup(System::Runtime::Serialization::SerializationInfo ^info, System::Runtime::Serialization::StreamingContext context)
		{
			m_strName = info->GetString("m_strName");
			m_vecMessageList = (System::Collections::Generic::List<unsigned int> ^)info->GetValue("m_vecMessageList", System::Collections::Generic::List<unsigned int>::typeid);
		}


		void AddMessage(LogMessage ^pMsg);

		void AddChildGroup(LogMessageGroup ^pGroup)
		{
			// Add all messages currently in the other group
			m_vecMessageList->AddRange(pGroup->m_vecMessageList);

			// Listen to the group's OnMessageAdded event, so that we get all future messages
			pGroup->OnMessageAdded += gcnew OnMessageAddedDelegate(this, &LogMessageGroup::OnChildMessageAdded);
		}

		void OnChildMessageAdded(unsigned int uiID)
		{
			m_vecMessageList->Add(uiID);
		}

	};
}

#endif